 import axios from  'axios';
import {fromJS} from 'immutable';
import * as constants from './constants';
//定义方法
 const  changeHtml=(data)=>({
     type:constants.CHANGE_HTML,
     Data:fromJS(data)  //吧数据转为immutable类型
 });
 const isChina=(s)=>{                               //判断url中是否包含中文 是的话再继续转义
     if(/[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/gi.exec(s)){
         return encodeURI(s);
     }else{return s}
 };
 export  const getHtmlContent=(url)=>{
     return (dispatch) => {
         axios.get(window.ip+'/getData'+isChina(url)).then((res)=>{
             dispatch(changeHtml(res.data.data[0]));
         }).catch(()=>{
             console.log('err-404');
         });
     }
 }